<?php

namespace Home\Controller;

use Think\Controller;
use User\Api\UserApi;

header('Access-Control-Allow-Origin:*');
header('Access-Control-Allow-Methods:*');
header('Access-Control-Allow-Headers:x-requested-with,content-type');

class ScriptController extends Controller
{


    /**
     * Notes:新增用户数据
     * @return [type] [description]
     */
    public function addUserList(){
        $total  = (int)I('total')+1000;
        empty($total) && datamsg(0,'请输入正确的数量');

        $User = new UserApi;
        for($i=1000;$i<$total;$i++){
            $mobile = rand(130,189).rand(1000,9999).$i;
            $User->register($mobile,'123456');
        }
        datamsg(1,'数据插入成功');
    }

    /**
     * Notes:新增订单数据
     * @return [type] [description]
     */
    public function addOrder(){

        $total  = (int)I('total')+1000;
        $status = I('status');
        empty($total) && datamsg(0,'请输入正确的数量');
        $driver_list    = D('siji')->field('id,xingming,dianhua,openid')->select();
        $driver_list    = array_index_value($driver_list,'id','');

        for($i=1000;$i<$total;$i++){
            //司机信息
            $arr            = array('170','171','172','173','174','175');
            $rand1          = $arr[array_rand($arr,1)];
            $mobile = rand(130,189).rand(1000,9999).$i;
            $driver_list1    = $driver_list[$rand1];
            //路线信息
            $rand2   = rand(75,79);
            $path=D("price")->where("id=".$rand2)->find();
            $time   =time()-rand(1,10000);
            $orderid            = unqiueNumber();
            $data['openid']     = $driver_list1['openid'];
            $data['start']      = $path['from_city'];
            $data['end']        = $path['end_city'];
            $data['price']      = $path['price'];
            $data['starttime']  = date('Y-m-d H:i:s',$time);
            $data['addtime']    = time();
            $data['num']        = 1;
            $data['orderid']    = $orderid;
            $data['pathid']     = $rand2;
            $data['guding']     = '武汉';
            $data['dianhua']    = $driver_list1['dianhua'];
            $data['xingming']   = $driver_list1['xingming'];
            $data['pay_statu']  = 1;
            $data['pay_status_sk']  = 1;
            $data['status']     = $status;
            $data['mobile']     = $mobile;

            D('xllog')->add($data);
        }
        datamsg(1,'成功');
    }

    /**
     * Notes:车辆经营上线下线
     * @return [json] [description]
     */
    public function driver(){
        $total   = (int)I('total')+1000;
        $status  = (int)I('status')?(int)I('status'):0;
        empty($total) && datamsg(0,'请输入正确的数量');
        $driver_list    = D('siji')->field('id,xingming,dianhua,openid')->select();
        $driver_list    = array_index_value($driver_list,'id','');
        for($i=1000;$i<$total;$i++){
            $arr            = array('166','165','163','161','160');
            $rand1          = $arr[array_rand($arr,1)];

            $data   =   array(
                'openid'         => $driver_list[$rand1]['openid'],
                'create_time'    => time()-rand(1000,10000),
                'status'         => $status,
            );

            D('cheliang_info')->add($data);
        }
        datamsg(1,'数据插入成功');
    }

    /**
     * Notes:车辆定位信息
     * @return [type] [description]
     */
    public function carLocating(){
        $total   = (int)I('total')+1000;
        empty($total) && datamsg(0,'请输入正确的数量');

        $driver_list    = D('siji')->field('id,xingming,dianhua,openid')->select();
        $driver_list    = array_index_value($driver_list,'id','');
        $arr            = array('166','165','163','161','160');

        $order_list     = D('xllog')->field('id,openid,orderid')->select();
        $order_list     = array_index_value($order_list,'id','');

        for($i=1000;$i<$total;$i++){
            $rand1          = $arr[array_rand($arr,1)];
            $order_arr      = rand(1800,2004);
            $rand2          = $order_list[$order_arr];
            $data   =   array(
                'openid'         => $driver_list[$rand1]['openid'],
                'address'        => 1101101,
                'orderid'        => $rand2['orderid'],
                'vehicleno'      => '鄂A12345',
                'positiontime'   => time()-rand(1,100000),
                'longitude'      => rand(10600000,11400000)/100000,
                'latitude'       => rand(3000000,4000000)/100000,
            );
            D('car_locating_information')->add($data);
        }
        datamsg(1,'数据插入成功');
    }


    /**
     * Notes:司机定位信息
     * @return [type] [description]
     */
    public function locating(){
        $total   = (int)I('total')+1000;
        empty($total) && datamsg(0,'请输入正确的数量');

        $driver_list    = D('siji')->field('id,xingming,dianhua,openid')->select();
        $driver_list    = array_index_value($driver_list,'id','');
        $arr            = array('166','165','163','161','160');

        $order_list     = D('xllog')->field('id,openid,orderid')->select();
        $order_list     = array_index_value($order_list,'id','');

        for($i=1000;$i<$total;$i++){
            $rand1          = $arr[array_rand($arr,1)];
            $order_arr      = rand(1800,2004);
            $rand2          = $order_list[$order_arr];
            $data   =   array(
                'openid'         => $driver_list[$rand1]['openid'],
                'address'        => 1101101,
                'orderid'        => $rand2['orderid'],
                'vehicleno'      => '鄂A12345',
                'positiontime'   => time()-rand(1,100000),
                'longitude'      => rand(10600000,11400000)/100000,
                'latitude'       => rand(3000000,4000000)/100000,
            );
            D('locating_information')->add($data);
        }
        datamsg(1,'数据插入成功');
    }

    /**
     * Notes:乘客投诉信息
     * @return [type] [description]
     */
    public function complaint(){
        $total   = (int)I('total');
        empty($total) && datamsg(0,'请输入正确的数量');

        $order_list     = D('xllog')->field('id,openid,orderid')->select();
        $order_list     = array_index_value($order_list,'id','');

        for($i=1;$i<$total;$i++){
            $order_arr      = rand(1800,2004);
            $rand2          = $order_list[$order_arr];
            $data   =   array(
                'orderid'        => $rand2['orderid'],
                'companyid'      => null,
                'complainttime'  => time()-rand(1,100000),
                'detail'         => '司机迟到'.$i.'分钟',
                'result'         => null,
            );

            D('complaint')->add($data);
        }
        datamsg(1,'数据插入成功');
    }

    /**
     * Notes:乘客评价信息
     * @return [type] [description]
     */
    public function evaluates(){
        $total   = (int)I('total')+1000;
        empty($total) && datamsg(0,'请输入正确的数量');

        $order_list     = D('xllog')->field('id,openid,orderid,dianhua')->select();
        $order_list     = array_index_value($order_list,'id','');

        for($i=1000;$i<$total;$i++){
            $mobile = rand(130,189).rand(1000,9999).$i;
            $order_arr      = rand(1800,2004);
            $rand2  = $order_list[$order_arr];
            $count1 = rand(3,5);
            $count2 = rand(3,5);
            $count3 = rand(3,5);
            $data   =   array(
                'companyid'      => null,
                'userphone'      => $mobile,
                'driveropenid'   => $rand2['dianhua'],
                'orderid'        => $rand2['orderid'],
                'evaluatetime'   => time()-rand(1,100000),
                'servicescore'   => $count1,
                'driverscore'    => $count2,
                'vehiclescore'   => $count3,
                'detail'         => '不错的体验',
            );
            D('evaluates')->add($data);
        }
        datamsg(1,'数据插入成功');
    }

    /**
     * Notes:驾驶员信誉信息
     * @return [type] [description]
     */
    public function evaluate_comment(){
        $total   = (int)I('total');
        $type    = (int)I('type');
        empty($total) && datamsg(0,'请输入正确的数量');

        $order_list     = D('xllog')->field('id,openid,orderid,dianhua')->select();
        $order_list     = array_index_value($order_list,'id','');

        for($i=1;$i<=$total;$i++){
            $order_arr      = rand(1800,2004);
            $rand2  = $order_list[$order_arr];
            $count1 = rand(3,5);
            $data   =   array(
                'type'           => $type,
                'openid'         => $rand2['openid'],
                'count'          => $count1,
                'info'           => '增加'.$count1.'信誉分',
                'create_time'    => time()-rand(1,100000),
            );
            D('evaluate_comment')->add($data);
        }
        datamsg(1,'数据插入成功');
    }
}
